'use client'; import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; import type { StockPriceRow } from '@/types/stock'; import { changeDirection, formatNumber } from '@/lib/utils/stock'; // recharts(d3 포함) 실제 렌더 본체 — StockPriceChart 가 next/dynamic({ssr:false})로 지연 로드. // 색은 래퍼 dir 클래스(.stock-chart--up/down/flat)의 CSS color 를 currentColor 로 상속 // (recharts stroke/fill 은 SVG presentation attribute 라 var() 미해석 → currentColor 사용). type Props = { // GetDetail.recentPrices — 최신순(newest-first). 호출부에서 length>=2 보장. prices: StockPriceRow[]; name: string; }; export default function PriceChartInner({ prices, name }: Props) { // 과거→최신 순서로 뒤집어 종가 시계열 구성 const series = [...prices].reverse().map(p => ({ date: p.tradingDate, close: p.close })); const dir = changeDirection(series[series.length - 1].close - series[0].close); return (
최근 {series.length}일 종가 추이
{ const n = Array.isArray(value) ? Number(value[0]) : Number(value); return [formatNumber(Number.isFinite(n) ? n : null), '종가']; }} labelFormatter={(label) => String(label)} />
); }